# -*- makefile -*-
# vim:set ft=make:

# recent version.h required for any kip*.o files
$(filter kip%.o,$(OBJ_ABI)): $(VERSION)

$(VERSION): FORCE
		$(GENVER_MESSAGE)
		$(VERBOSE)v=`git rev-parse --verify --short HEAD 2>/dev/null`;\
		if [ -z "$$v" ]; then                                  \
		   v=`svnversion -nc $(srcdir)`;                       \
		   if [ -n "$$v" ]; then                               \
		     v=$${v%[A-Z]}; v="r$${v#*:}";                     \
		   else                                                \
		     v=`hg id 2>/dev/null`;                            \
		     if [ -n "$$v" ]; then                             \
		       v="$${v% *}";                                   \
		     fi                                                \
		   fi                                                  \
		fi;                                                    \
		echo "#define CODE_VERSION \"$$v\"" > $@
		$(VERBOSE)echo "#define BUILD_DATE \"$$(date)\"" >> $@
		$(VERBOSE)if [ -e .build_nr ]; then                    \
		  nr=$$(($$(cat .build_nr) + 1));                      \
		else                                                   \
		  nr=1;                                                \
		fi;                                                    \
		echo $$nr > .build_nr;                                 \
		echo "#define BUILD_NR \"$$nr\"" >> $@

clean-VERSION:
		rm -f $(VERSION)
